package com.example.myapplication.apter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.Config.TokenBean;
import com.example.myapplication.Garbagesorting.NewsdetailscategoryActivity;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.NewscategorylistBean;

import java.util.List;

public class NewscategorylistApter extends RecyclerView.Adapter<NewscategorylistApter.MyHolder> {
    private Context context;
    private List<NewscategorylistBean.RowsBean> list;

    public NewscategorylistApter(Context context, List<NewscategorylistBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public NewscategorylistApter.MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_newscategorylist, null);
        return new NewscategorylistApter.MyHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull NewscategorylistApter.MyHolder holder, int position) {
        Glide.with(context).load(TokenBean.IP+list.get(position).getImgUrl()).into(holder.NewscategorylistIMG);
        holder.Newscategorylist_title.setText(list.get(position).getTitle());
        holder.NewscategorylistData.setText(list.get(position).getCreateTime());
        //新闻详情
        holder.ReNewscategorylist.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, NewsdetailscategoryActivity.class);
                intent.putExtra("NewsdetailscategoryID",String.valueOf(list.get(position).getId()));
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {
        ImageView NewscategorylistIMG;
        TextView Newscategorylist_title;
        TextView NewscategorylistData;
        RelativeLayout ReNewscategorylist;

        public MyHolder(@NonNull View itemView) {
            super(itemView);
            NewscategorylistIMG = itemView.findViewById(R.id.NewscategorylistIMG);
            Newscategorylist_title = itemView.findViewById(R.id.Newscategorylist_title);
            NewscategorylistData = itemView.findViewById(R.id.NewscategorylistData);
            ReNewscategorylist = itemView.findViewById(R.id.ReNewscategorylist);
        }
    }
}


